﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PRE.Report_Catalog
{
    public partial class FrmBangdiem_Theokhoa : PRE.Catalog.FrmBase
    {
        DAL.EntitesDAL.BangdiemDAL _dal = new DAL.EntitesDAL.BangdiemDAL();
        DAL.EntitesDAL.KhoahocDAL _dal1 = new DAL.EntitesDAL.KhoahocDAL();

        public FrmBangdiem_Theokhoa()
        {
            InitializeComponent();
        }

        private void FrmBangdiem_Theokhoa_Load(object sender, EventArgs e)
        {
            PerformRefresh();
        }


        #region Override

        /// <summary>
        /// Perform when click add button
        /// </summary>
        protected override void PerformAdd()
        {
            base.PerformAdd();
        }

        /// <summary>
        /// Perform when click cancel button
        /// </summary>
        protected override void PerformCancel()
        {
            base.PerformCancel();
        }

        /// <summary>
        /// Perform when click delete button
        /// </summary>
        /// <returns></returns>
        protected override void PerformDelete()
        {
            base.PerformDelete();
        }

        /// <summary>
        /// Perform when click edit button
        /// </summary>
        protected override void PerformEdit()
        {
            base.PerformEdit();
        }

        /// <summary>
        /// Perform when click print button
        /// </summary>
        protected override void PerformPrint()
        {
            var frm = new Report.FrmReport_Base();
            frm.Text = "In: " + Text;
            var rpt = new Report.XRBangdiem_Theokhoa();
            
            rpt.parDau.Value = txtDau.Text;
            rpt.parRot.Value = txtRot.Text;

            rpt.DataSource = _dal.Select_Bangdiem_Theokhoa(cboKhoahoc.EditValue + "");
            frm.SetReport(rpt);
            frm.Show();
            frm.Activate();

            base.PerformPrint();
        }

        /// <summary>
        /// Load data or perform when click refresh button
        /// </summary>
        protected override void PerformRefresh()
        {
            ChangeStatus_TK();
            LoadData();
            base.PerformRefresh();
        }

        /// <summary>
        /// Perform when click save button
        /// </summary>
        protected override void PerformSave()
        {
            base.PerformSave();
        }

        /// <summary>
        /// Reset all input control
        /// </summary>
        protected override void ResetText()
        {
            base.ResetText();
        }

        /// <summary>
        /// Clear data binding
        /// </summary>
        protected override void ClearDataBindings()
        {
            base.ClearDataBindings();
        }

        /// <summary>
        /// Add data binding
        /// </summary>
        protected override void DataBindingControl()
        {
            base.DataBindingControl();
        }

        /// <summary>
        /// Set read only control on form
        /// </summary>
        /// <param name="isReadOnly">Read only is trule else normal</param>
        protected override void ReadOnlyControl(bool isReadOnly = true)
        {
            base.ReadOnlyControl(isReadOnly);
        }

        protected override void PerformSearch()
        {
            base.PerformSearch();
        }


        /// <summary>
        /// Update object
        /// </summary>
        /// <returns>True if successful else false</returns>
        protected override bool UpdateObject()
        {
            return base.UpdateObject();
        }

        /// <summary>
        /// Insert object
        /// </summary>
        /// <returns>True if successful else false</returns>
        protected override bool InsertObject()
        {
            return base.InsertObject();
        }

        /// <summary>
        /// Load data
        /// </summary>
        protected override void LoadData()
        {
            _dtb = _dal1.Select();

            if (_dtb != null)
            {
                cboKhoahoc.Properties.DataSource = _dtb;
            }

            cboKhoahoc.ItemIndex = -1;

            base.LoadData();
        }
        #endregion

        private void cboKhoahoc_EditValueChanged(object sender, EventArgs e)
        {
            string makhoa = cboKhoahoc.EditValue + "";
            _dtb = _dal.Select_Bangdiem_Theokhoa(makhoa);

            if (_dtb != null)
            {
                grcMain.DataSource = _dtb;

                int dau = (int)_dtb.Compute("Count(MaHV)", "Ghichu='Đ'");
                int rot = (int)_dtb.Compute("Count(MaHV)", "Ghichu='H'");

                txtDau.Text = dau.ToString("#,0");
                txtRot.Text = rot.ToString("#,0");
            }
        }

    }
}
